﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using System.Reflection;
using log4net;

namespace AnyOffice.general.person_info
{
    public partial class mypriv : ModulePage
    {


        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                UserCache cache = new UserCache();
                this.txtUserId2.Text = cache.UserId2;
                this.litNavTitle.Text = cache.UserName;
                this.litPrivName.Text = cache.PrivName;
                string postPriv = cache.PostPriv;
                if (postPriv != null)
                {
                    if (!(postPriv == "0"))
                    {
                        if (postPriv == "1")
                        {
                            this.litPostDept.Text = "全体部门";
                        }
                        else if (postPriv == "2")
                        {
                            DataTable table = new UsersDao().SelectByUserId(base.Conn, base.User.Identity.Name);
                            if (table.Rows.Count > 0)
                            {
                                this.litPostDept.Text = "指定部门：" + ((table.Rows[0]["PostDeptNames"] != DBNull.Value) ? table.Rows[0]["PostDeptNames"].ToString() : "");
                            }
                        }
                    }
                    else
                    {
                        this.litPostDept.Text = "本部门";
                    }
                }
                if (cache.EmailCapacity == 0)
                {
                    this.litEmailCapacity.Text = "不限制容量";
                }
                else
                {
                    this.litEmailCapacity.Text = cache.EmailCapacity.ToString() + "M";
                }
                if (cache.FolderCapacity == 0)
                {
                    this.litFolderCapacity.Text = "不限制容量";
                }
                else
                {
                    this.litFolderCapacity.Text = cache.FolderCapacity.ToString() + "M";
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                try
                {
                    if (this.txtUserId2.Text == base.User.Identity.Name)
                    {
                        this.litMessage.Text = base.ShowPrompt("用户名和别名不能相同", "mypriv.aspx");
                    }
                    else if (new UsersDao().SetUserId2(base.Conn, base.User.Identity.Name, this.txtUserId2.Text))
                    {
                        UserCache.Update(base.User.Identity.Name);
                        this.litMessage.Text = base.ShowPrompt("已保存修改", "index.aspx");
                    }
                    else
                    {
                        this.litMessage.Text = base.ShowPrompt("用户名或别名 " + this.txtUserId2.Text + " 已存在", "mypriv.aspx");
                    }
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                    this.litMessage.Text = base.ShowPrompt("已保存修改", "index.aspx");
                }
            }
        }

 
    }
}
